app.controller('QRListCtrl', function ($scope, ajax, $stateParams, $modal, toaster) {

	$scope.startId = $stateParams.startId;
	$scope.reload = $scope.page.loader('starting/bk/' + $scope.startId + '/{pageIndex}/{pageSize}/qr');
	$scope.$on('pageIndex', function (event, p) { $scope.reload(p, $scope.queryMap); });
	$scope.reload(1);
	$scope.queryMap = {};
	$scope.query = function () { $scope.reload(1, $scope.queryMap); };

	$scope.open = function (qr) {
		$modal.open({
			templateUrl: 'template/booking/start/showQR.html?v=58fb3bc51e',
			controller: 'ModalCtrl',
			size: 'lg',
			resolve: {
				param: function () {
					return {
						"start": qr.start.name,
						"terminal": qr.terminalName,
						"url": qr.content,
						"qr": qr.qr
					};
				}
			}
		});
	};

	$scope.del = function (qr) {
		var modalInstance = $scope.delModal('sm', qr, 'delete');
		modalInstance.result.then(function (param) {
			ajax.del('starting/bk/qr/' + param.data.id + '/delete', function (result) {
				if (result && result.code == 200) {
					toaster.pop('success', '成功', '删除成功。');
					$scope.reload(1);
				} else {
					toaster.pop('error', '错误', '删除失败！');
				}
			}, function () {
				toaster.pop('error', '错误', '无法连接到服务器，删除失败！');
			});
		});
	};
});
